{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{<Name full_name='helpers.test2.a_func', description='def a_func'>}\n",
      "def a_func():\n",
      "    a = 1\n",
      "    b = 2 * a\n",
      "    c = a * foo() + b * 3\n",
      "    print(b, c)\n"
     ]
    }
   ],
   "source": [
    "import ast\n",
    "import jedi\n",
    "\n",
    "project_dir = \"src\"\n",
    "file_name = \"jedi_test.py\"\n",
    "\n",
    "file_contents = open(f\"{project_dir}/{file_name}\").read()\n",
    "\n",
    "project = jedi.Project(path=project_dir)\n",
    "script = jedi.Script(file_contents, path=file_name, project=project)\n",
    "tree = ast.parse(file_contents)\n",
    "\n",
    "function_definitions = set()\n",
    "\n",
    "for node in ast.walk(tree):\n",
    "    if node.__class__.__name__ == 'Call':\n",
    "        new_function_definitions = script.goto(\n",
    "            node.lineno, \n",
    "            node.col_offset,\n",
    "            follow_imports=True,\n",
    "            follow_builtin_imports=True,\n",
    "        )\n",
    "        function_definitions.update(new_function_definitions)\n",
    "\n",
    "print(function_definitions)\n",
    "\n",
    "for function_definition in function_definitions:\n",
    "    start_line, _ = function_definition.get_definition_start_position()\n",
    "    end_line, _ = function_definition.get_definition_end_position()\n",
    "    module_contents = open(function_definition.module_path).read()\n",
    "    print(\"\\n\".join(module_contents.split(\"\\n\")[max(0, start_line - 1): end_line]))\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "/home/kevin/sweep/sweepai/logn/logn.py\n",
      "/home/kevin/.cache/pypoetry/virtualenvs/sweepai-u_CIt3kb-py3.10/lib/python3.10/site-packages/fastapi/applications.py\n",
      "/usr/lib/python3.10/tracemalloc.py\n",
      "/home/kevin/sweep/tests/notebooks/sweepai/api.py\n",
      "/home/kevin/sweep/tests/notebooks/sweepai/api.py\n",
      "/home/kevin/sweep/tests/notebooks/sweepai/api.py\n",
      "/home/kevin/sweep/tests/notebooks/sweepai/api.py\n",
      "/home/kevin/sweep/tests/notebooks/sweepai/api.py\n",
      "/home/kevin/sweep/tests/notebooks/sweepai/api.py\n",
      "/usr/lib/python3.10/threading.py\n",
      "/home/kevin/sweep/tests/notebooks/sweepai/api.py\n",
      "/home/kevin/sweep/sweepai/logn/logn.py\n",
      "/home/kevin/sweep/sweepai/handlers/on_check_suite.py\n",
      "/home/kevin/sweep/sweepai/logn/logn.py\n",
      "/home/kevin/.cache/pypoetry/virtualenvs/sweepai-u_CIt3kb-py3.10/lib/python3.10/site-packages/jedi/third_party/typeshed/stdlib/2and3/time.pyi\n",
      "/home/kevin/sweep/tests/notebooks/sweepai/api.py\n",
      "/home/kevin/sweep/tests/notebooks/sweepai/api.py\n",
      "/home/kevin/sweep/tests/notebooks/sweepai/api.py\n",
      "/usr/lib/python3.10/threading.py\n",
      "/home/kevin/sweep/tests/notebooks/sweepai/api.py\n",
      "/usr/lib/python3.10/threading.py\n",
      "/home/kevin/sweep/tests/notebooks/sweepai/api.py\n",
      "/usr/lib/python3.10/threading.py\n",
      "/home/kevin/sweep/tests/notebooks/sweepai/api.py\n",
      "/home/kevin/sweep/sweepai/logn/logn.py\n",
      "/home/kevin/sweep/tests/notebooks/sweepai/api.py\n",
      "/usr/lib/python3.10/threading.py\n",
      "/home/kevin/sweep/tests/notebooks/sweepai/api.py\n",
      "/usr/lib/python3.10/threading.py\n",
      "/home/kevin/sweep/tests/notebooks/sweepai/api.py\n",
      "/usr/lib/python3.10/threading.py\n",
      "/home/kevin/sweep/tests/notebooks/sweepai/api.py\n",
      "/home/kevin/sweep/sweepai/health.py\n",
      "/home/kevin/sweep/sweepai/logn/logn.py\n",
      "/home/kevin/sweep/sweepai/utils/github_utils.py\n",
      "/home/kevin/sweep/tests/notebooks/sweepai/api.py\n",
      "/home/kevin/sweep/sweepai/config/client.py\n",
      "/home/kevin/.cache/pypoetry/virtualenvs/sweepai-u_CIt3kb-py3.10/lib/python3.10/site-packages/jedi/third_party/typeshed/stdlib/3/builtins.pyi\n",
      "/usr/lib/python3.10/hashlib.py\n",
      "/home/kevin/.cache/pypoetry/virtualenvs/sweepai-u_CIt3kb-py3.10/lib/python3.10/site-packages/loguru/__init__.py\n",
      "/home/kevin/sweep/sweepai/handlers/on_ticket.py\n",
      "/home/kevin/.cache/pypoetry/virtualenvs/sweepai-u_CIt3kb-py3.10/lib/python3.10/site-packages/loguru/__init__.py\n",
      "/home/kevin/sweep/sweepai/handlers/on_comment.py\n",
      "/home/kevin/sweep/sweepai/logn/logn.py\n",
      "/home/kevin/sweep/sweepai/logn/logn.py\n",
      "/home/kevin/sweep/sweepai/logn/logn.py\n",
      "/home/kevin/sweep/sweepai/core/vector_db.py\n",
      "/usr/lib/python3.10/ctypes/__init__.py\n",
      "/usr/lib/python3.10/ctypes/__init__.py\n",
      "/home/kevin/sweep/sweepai/logn/logn.py\n",
      "/home/kevin/sweep/tests/notebooks/sweepai/api.py\n",
      "/home/kevin/sweep/sweepai/utils/safe_pqueue.py\n",
      "/home/kevin/.cache/pypoetry/virtualenvs/sweepai-u_CIt3kb-py3.10/lib/python3.10/site-packages/jedi/third_party/typeshed/stdlib/3/builtins.pyi\n",
      "/usr/lib/python3.10/threading.py\n",
      "/home/kevin/sweep/tests/notebooks/sweepai/api.py\n",
      "/home/kevin/sweep/tests/notebooks/sweepai/api.py\n",
      "/home/kevin/sweep/tests/notebooks/sweepai/api.py\n",
      "/home/kevin/.cache/pypoetry/virtualenvs/sweepai-u_CIt3kb-py3.10/lib/python3.10/site-packages/jedi/third_party/typeshed/stdlib/3/builtins.pyi\n",
      "/home/kevin/sweep/tests/notebooks/sweepai/api.py\n",
      "/home/kevin/sweep/tests/notebooks/sweepai/api.py\n",
      "/home/kevin/sweep/tests/notebooks/sweepai/api.py\n",
      "/usr/lib/python3.10/ctypes/__init__.py\n",
      "/home/kevin/.cache/pypoetry/virtualenvs/sweepai-u_CIt3kb-py3.10/lib/python3.10/site-packages/jedi/third_party/typeshed/stdlib/3/builtins.pyi\n",
      "/home/kevin/sweep/sweepai/logn/logn.py\n",
      "/home/kevin/sweep/tests/notebooks/sweepai/api.py\n",
      "/home/kevin/sweep/tests/notebooks/sweepai/api.py\n",
      "/home/kevin/sweep/tests/notebooks/sweepai/api.py\n",
      "/home/kevin/sweep/tests/notebooks/sweepai/api.py\n",
      "/home/kevin/sweep/sweepai/logn/logn.py\n",
      "/home/kevin/.cache/pypoetry/virtualenvs/sweepai-u_CIt3kb-py3.10/lib/python3.10/site-packages/fastapi/exceptions.py\n",
      "/home/kevin/sweep/tests/notebooks/sweepai/api.py\n",
      "/home/kevin/sweep/sweepai/logn/logn.py\n",
      "/usr/lib/python3.10/hashlib.py\n",
      "/usr/lib/python3.10/ctypes/__init__.py\n",
      "/home/kevin/.cache/pypoetry/virtualenvs/sweepai-u_CIt3kb-py3.10/lib/python3.10/site-packages/jedi/third_party/typeshed/stdlib/3/builtins.pyi\n",
      "/home/kevin/sweep/sweepai/events.py\n",
      "/home/kevin/sweep/sweepai/utils/github_utils.py\n",
      "/home/kevin/sweep/tests/notebooks/sweepai/api.py\n",
      "/home/kevin/sweep/sweepai/logn/logn.py\n",
      "/usr/lib/python3.10/threading.py\n",
      "/home/kevin/sweep/tests/notebooks/sweepai/api.py\n",
      "/home/kevin/sweep/sweepai/logn/logn.py\n",
      "/home/kevin/sweep/sweepai/events.py\n",
      "/home/kevin/sweep/tests/notebooks/sweepai/api.py\n",
      "/home/kevin/sweep/sweepai/logn/logn.py\n",
      "/home/kevin/sweep/sweepai/events.py\n",
      "/home/kevin/sweep/sweepai/logn/logn.py\n",
      "/home/kevin/sweep/sweepai/events.py\n",
      "/home/kevin/sweep/sweepai/logn/logn.py\n",
      "/home/kevin/sweep/sweepai/events.py\n",
      "/home/kevin/.cache/pypoetry/virtualenvs/sweepai-u_CIt3kb-py3.10/lib/python3.10/site-packages/jedi/third_party/typeshed/stdlib/3/builtins.pyi\n",
      "/home/kevin/sweep/sweepai/logn/logn.py\n",
      "/home/kevin/sweep/sweepai/events.py\n",
      "/home/kevin/sweep/sweepai/logn/logn.py\n",
      "/home/kevin/sweep/sweepai/events.py\n",
      "/home/kevin/sweep/sweepai/utils/github_utils.py\n",
      "/home/kevin/sweep/tests/notebooks/sweepai/api.py\n",
      "/home/kevin/sweep/tests/notebooks/sweepai/api.py\n",
      "/home/kevin/sweep/tests/notebooks/sweepai/api.py\n",
      "/home/kevin/sweep/sweepai/events.py\n",
      "/home/kevin/sweep/sweepai/utils/event_logger.py\n",
      "/home/kevin/sweep/sweepai/utils/event_logger.py\n",
      "/home/kevin/sweep/sweepai/events.py\n",
      "/home/kevin/sweep/sweepai/events.py\n",
      "/home/kevin/sweep/sweepai/events.py\n",
      "/home/kevin/sweep/tests/notebooks/sweepai/api.py\n",
      "/home/kevin/sweep/sweepai/utils/chat_logger.py\n",
      "/home/kevin/sweep/sweepai/logn/logn.py\n",
      "/home/kevin/sweep/tests/notebooks/sweepai/api.py\n",
      "/home/kevin/.cache/pypoetry/virtualenvs/sweepai-u_CIt3kb-py3.10/lib/python3.10/site-packages/jedi/third_party/typeshed/stdlib/3/builtins.pyi\n",
      "/home/kevin/sweep/tests/notebooks/sweepai/api.py\n",
      "/usr/lib/python3.10/threading.py\n",
      "/home/kevin/sweep/tests/notebooks/sweepai/api.py\n",
      "/home/kevin/sweep/sweepai/logn/logn.py\n",
      "/home/kevin/sweep/tests/notebooks/sweepai/api.py\n",
      "/home/kevin/sweep/sweepai/utils/github_utils.py\n",
      "/home/kevin/sweep/tests/notebooks/sweepai/api.py\n",
      "/home/kevin/sweep/tests/notebooks/sweepai/api.py\n",
      "/home/kevin/.cache/pypoetry/virtualenvs/sweepai-u_CIt3kb-py3.10/lib/python3.10/site-packages/jedi/third_party/typeshed/stdlib/2and3/time.pyi\n",
      "/home/kevin/.cache/pypoetry/virtualenvs/sweepai-u_CIt3kb-py3.10/lib/python3.10/site-packages/jedi/third_party/typeshed/stdlib/3/builtins.pyi\n",
      "/home/kevin/sweep/sweepai/config/client.py\n",
      "/home/kevin/sweep/tests/notebooks/sweepai/api.py\n",
      "/home/kevin/sweep/sweepai/utils/github_utils.py\n",
      "/home/kevin/sweep/tests/notebooks/sweepai/api.py\n",
      "/home/kevin/sweep/tests/notebooks/sweepai/api.py\n",
      "/home/kevin/sweep/tests/notebooks/sweepai/api.py\n",
      "/home/kevin/sweep/tests/notebooks/sweepai/api.py\n",
      "/home/kevin/sweep/sweepai/utils/buttons.py\n",
      "/home/kevin/sweep/sweepai/utils/buttons.py\n",
      "/home/kevin/sweep/tests/notebooks/sweepai/api.py\n",
      "/home/kevin/sweep/sweepai/utils/buttons.py\n",
      "/home/kevin/sweep/sweepai/logn/logn.py\n",
      "/home/kevin/sweep/tests/notebooks/sweepai/api.py\n",
      "/home/kevin/sweep/sweepai/logn/logn.py\n",
      "/home/kevin/sweep/tests/notebooks/sweepai/api.py\n",
      "/home/kevin/sweep/sweepai/logn/logn.py\n",
      "/home/kevin/sweep/tests/notebooks/sweepai/api.py\n",
      "/home/kevin/sweep/tests/notebooks/sweepai/api.py\n",
      "/home/kevin/sweep/sweepai/core/entities.py\n",
      "/home/kevin/sweep/tests/notebooks/sweepai/api.py\n",
      "/home/kevin/sweep/sweepai/handlers/create_pr.py\n",
      "/home/kevin/sweep/tests/notebooks/sweepai/api.py\n",
      "/home/kevin/sweep/sweepai/utils/event_logger.py\n",
      "/home/kevin/sweep/sweepai/utils/event_logger.py\n",
      "/home/kevin/sweep/sweepai/utils/search_utils.py\n",
      "/home/kevin/sweep/sweepai/handlers/create_pr.py\n",
      "/home/kevin/sweep/sweepai/utils/search_utils.py\n",
      "/home/kevin/sweep/sweepai/utils/buttons.py\n",
      "/home/kevin/sweep/sweepai/utils/buttons.py\n",
      "/home/kevin/sweep/tests/notebooks/sweepai/api.py\n",
      "/home/kevin/sweep/sweepai/utils/event_logger.py\n",
      "/home/kevin/sweep/sweepai/utils/event_logger.py\n",
      "/home/kevin/sweep/sweepai/utils/chat_logger.py\n",
      "/home/kevin/sweep/tests/notebooks/sweepai/api.py\n",
      "/home/kevin/sweep/tests/notebooks/sweepai/api.py\n",
      "/home/kevin/sweep/tests/notebooks/sweepai/api.py\n",
      "/home/kevin/sweep/sweepai/handlers/create_pr.py\n",
      "/home/kevin/sweep/sweepai/logn/logn.py\n",
      "/home/kevin/sweep/tests/notebooks/sweepai/api.py\n",
      "/home/kevin/sweep/tests/notebooks/sweepai/api.py\n",
      "/home/kevin/sweep/tests/notebooks/sweepai/api.py\n",
      "/home/kevin/sweep/tests/notebooks/sweepai/api.py\n",
      "/home/kevin/sweep/tests/notebooks/sweepai/api.py\n",
      "/home/kevin/sweep/sweepai/utils/buttons.py\n",
      "/home/kevin/sweep/tests/notebooks/sweepai/api.py\n",
      "/home/kevin/sweep/tests/notebooks/sweepai/api.py\n",
      "/home/kevin/sweep/tests/notebooks/sweepai/api.py\n",
      "/home/kevin/sweep/sweepai/logn/logn.py\n",
      "/home/kevin/sweep/sweepai/logn/logn.py\n",
      "/home/kevin/sweep/sweepai/utils/github_utils.py\n",
      "/home/kevin/sweep/tests/notebooks/sweepai/api.py\n",
      "/home/kevin/sweep/tests/notebooks/sweepai/api.py\n",
      "/home/kevin/sweep/tests/notebooks/sweepai/api.py\n",
      "/home/kevin/sweep/tests/notebooks/sweepai/api.py\n",
      "/home/kevin/sweep/tests/notebooks/sweepai/api.py\n",
      "/home/kevin/sweep/sweepai/logn/logn.py\n",
      "/home/kevin/sweep/sweepai/utils/github_utils.py\n",
      "/home/kevin/sweep/tests/notebooks/sweepai/api.py\n",
      "/home/kevin/sweep/tests/notebooks/sweepai/api.py\n",
      "/home/kevin/sweep/tests/notebooks/sweepai/api.py\n",
      "/home/kevin/sweep/tests/notebooks/sweepai/api.py\n",
      "/home/kevin/.cache/pypoetry/virtualenvs/sweepai-u_CIt3kb-py3.10/lib/python3.10/site-packages/jedi/third_party/typeshed/stdlib/3/builtins.pyi\n",
      "/home/kevin/sweep/sweepai/logn/logn.py\n",
      "/home/kevin/sweep/sweepai/logn/logn.py\n",
      "/home/kevin/sweep/tests/notebooks/sweepai/api.py\n",
      "/home/kevin/.cache/pypoetry/virtualenvs/sweepai-u_CIt3kb-py3.10/lib/python3.10/site-packages/requests/__init__.py\n",
      "/home/kevin/sweep/sweepai/utils/event_logger.py\n",
      "/home/kevin/sweep/sweepai/utils/event_logger.py\n",
      "/home/kevin/sweep/tests/notebooks/sweepai/api.py\n",
      "/home/kevin/sweep/tests/notebooks/sweepai/api.py\n",
      "/home/kevin/sweep/sweepai/utils/github_utils.py\n",
      "/home/kevin/sweep/tests/notebooks/sweepai/api.py\n",
      "/home/kevin/sweep/tests/notebooks/sweepai/api.py\n",
      "/home/kevin/sweep/tests/notebooks/sweepai/api.py\n",
      "/home/kevin/.cache/pypoetry/virtualenvs/sweepai-u_CIt3kb-py3.10/lib/python3.10/site-packages/jedi/third_party/typeshed/stdlib/3/builtins.pyi\n",
      "/home/kevin/.cache/pypoetry/virtualenvs/sweepai-u_CIt3kb-py3.10/lib/python3.10/site-packages/jedi/third_party/typeshed/stdlib/2and3/time.pyi\n",
      "/home/kevin/sweep/tests/notebooks/sweepai/api.py\n",
      "/home/kevin/sweep/tests/notebooks/sweepai/api.py\n",
      "/home/kevin/sweep/sweepai/utils/buttons.py\n",
      "/home/kevin/sweep/tests/notebooks/sweepai/api.py\n",
      "/home/kevin/sweep/tests/notebooks/sweepai/api.py\n",
      "/home/kevin/sweep/tests/notebooks/sweepai/api.py\n",
      "/home/kevin/sweep/tests/notebooks/sweepai/api.py\n",
      "/home/kevin/sweep/tests/notebooks/sweepai/api.py\n",
      "/home/kevin/.cache/pypoetry/virtualenvs/sweepai-u_CIt3kb-py3.10/lib/python3.10/site-packages/jedi/third_party/typeshed/stdlib/3/builtins.pyi\n",
      "/home/kevin/sweep/sweepai/core/entities.py\n",
      "/home/kevin/sweep/tests/notebooks/sweepai/api.py\n",
      "/home/kevin/sweep/tests/notebooks/sweepai/api.py\n",
      "/home/kevin/sweep/tests/notebooks/sweepai/api.py\n",
      "/home/kevin/sweep/tests/notebooks/sweepai/api.py\n",
      "/home/kevin/.cache/pypoetry/virtualenvs/sweepai-u_CIt3kb-py3.10/lib/python3.10/site-packages/jedi/third_party/typeshed/stdlib/3/builtins.pyi\n",
      "/home/kevin/sweep/sweepai/core/entities.py\n",
      "/home/kevin/sweep/tests/notebooks/sweepai/api.py\n",
      "/home/kevin/sweep/tests/notebooks/sweepai/api.py\n",
      "/home/kevin/.cache/pypoetry/virtualenvs/sweepai-u_CIt3kb-py3.10/lib/python3.10/site-packages/jedi/third_party/typeshed/stdlib/3/builtins.pyi\n",
      "/home/kevin/sweep/sweepai/utils/github_utils.py\n",
      "/home/kevin/sweep/tests/notebooks/sweepai/api.py\n",
      "/home/kevin/sweep/tests/notebooks/sweepai/api.py\n",
      "/home/kevin/sweep/tests/notebooks/sweepai/api.py\n",
      "/home/kevin/sweep/tests/notebooks/sweepai/api.py\n",
      "/home/kevin/sweep/sweepai/utils/github_utils.py\n",
      "/home/kevin/sweep/tests/notebooks/sweepai/api.py\n",
      "/home/kevin/sweep/sweepai/config/client.py\n",
      "/home/kevin/sweep/tests/notebooks/sweepai/api.py\n",
      "/home/kevin/sweep/sweepai/config/client.py\n",
      "/home/kevin/sweep/tests/notebooks/sweepai/api.py\n",
      "/home/kevin/.cache/pypoetry/virtualenvs/sweepai-u_CIt3kb-py3.10/lib/python3.10/site-packages/jedi/third_party/typeshed/stdlib/2and3/time.pyi\n",
      "/home/kevin/sweep/tests/notebooks/sweepai/api.py\n",
      "/home/kevin/.cache/pypoetry/virtualenvs/sweepai-u_CIt3kb-py3.10/lib/python3.10/site-packages/jedi/third_party/typeshed/stdlib/2and3/time.pyi\n",
      "/home/kevin/.cache/pypoetry/virtualenvs/sweepai-u_CIt3kb-py3.10/lib/python3.10/site-packages/jedi/third_party/typeshed/stdlib/2and3/time.pyi\n",
      "/home/kevin/sweep/tests/notebooks/sweepai/api.py\n",
      "/home/kevin/sweep/tests/notebooks/sweepai/api.py\n",
      "/home/kevin/sweep/tests/notebooks/sweepai/api.py\n",
      "/home/kevin/sweep/sweepai/utils/buttons.py\n",
      "/home/kevin/sweep/tests/notebooks/sweepai/api.py\n",
      "/home/kevin/sweep/tests/notebooks/sweepai/api.py\n",
      "/usr/lib/python3.10/json/__init__.py\n",
      "/home/kevin/sweep/tests/notebooks/sweepai/api.py\n",
      "/home/kevin/sweep/tests/notebooks/sweepai/api.py\n",
      "/home/kevin/sweep/sweepai/logn/logn.py\n",
      "/home/kevin/sweep/sweepai/logn/logn.py\n",
      "/home/kevin/sweep/tests/notebooks/sweepai/api.py\n",
      "/home/kevin/sweep/tests/notebooks/sweepai/api.py\n",
      "/home/kevin/sweep/tests/notebooks/sweepai/api.py\n",
      "/home/kevin/sweep/tests/notebooks/sweepai/api.py\n",
      "/home/kevin/sweep/tests/notebooks/sweepai/api.py\n",
      "/home/kevin/sweep/tests/notebooks/sweepai/api.py\n",
      "/home/kevin/.cache/pypoetry/virtualenvs/sweepai-u_CIt3kb-py3.10/lib/python3.10/site-packages/jedi/third_party/typeshed/stdlib/3/builtins.pyi\n",
      "/home/kevin/sweep/tests/notebooks/sweepai/api.py\n",
      "/home/kevin/sweep/tests/notebooks/sweepai/api.py\n",
      "/home/kevin/sweep/tests/notebooks/sweepai/api.py\n",
      "/home/kevin/sweep/tests/notebooks/sweepai/api.py\n"
     ]
    }
   ],
   "source": [
    "import ast\n",
    "import os\n",
    "import sys\n",
    "import jedi\n",
    "from jedi.api.classes import Name\n",
    "\n",
    "project_dir = \"../..\"\n",
    "file_name = \"sweepai/api.py\"\n",
    "min_line = 101\n",
    "max_line = 110\n",
    "\n",
    "file_full_path = f\"{project_dir}/{file_name}\"\n",
    "\n",
    "file_contents = open(file_full_path).read()\n",
    "\n",
    "project_absolute_path = os.path.abspath(project_dir)\n",
    "\n",
    "BUILTIN_MODULES = [builtin_module_name.strip(\"_\") for builtin_module_name in sys.builtin_module_names] + [\"builtins\"]\n",
    "\n",
    "project = jedi.Project(path=project_absolute_path)\n",
    "script = jedi.Script(file_contents, path=file_name, project=project)\n",
    "tree = ast.parse(file_contents)\n",
    "\n",
    "function_definitions: set[Name] = set()\n",
    "\n",
    "for node in ast.walk(tree):\n",
    "    if node.__class__.__name__ == 'Call':\n",
    "        # if not min_line <= node.lineno <= max_line:\n",
    "        #     continue\n",
    "        new_function_definitions = script.goto(\n",
    "            node.lineno, \n",
    "            node.col_offset,\n",
    "            follow_imports=True,\n",
    "            follow_builtin_imports=True,\n",
    "        )\n",
    "        for function_definition in new_function_definitions:\n",
    "            print(function_definition.module_path)\n",
    "            if function_definition.full_name and any(function_definition.full_name.startswith(builtin_module) for builtin_module in BUILTIN_MODULES):\n",
    "                continue\n",
    "            if function_definition.type != \"function\" and function_definition.type != \"statement\":\n",
    "                continue\n",
    "            function_definitions.add(function_definition)\n",
    "\n",
    "# for function_definition in function_definitions:\n",
    "#     start_line, _ = function_definition.get_definition_start_position()\n",
    "#     end_line, _ = function_definition.get_definition_end_position()\n",
    "#     if os.path.exists(function_definition.module_path):\n",
    "#         module_contents = open(function_definition.module_path).read()\n",
    "#     else:\n",
    "#         module_contents = open(file_full_path).read()\n",
    "#     print(\"\\n\".join(module_contents.split(\"\\n\")[max(0, start_line - 1): end_line]))\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 104,
   "metadata": {},
   "outputs": [
    {
     "ename": "AttributeError",
     "evalue": "'Name' object has no attribute 'rtype'",
     "output_type": "error",
     "traceback": [
      "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[0;31mAttributeError\u001b[0m                            Traceback (most recent call last)",
      "Cell \u001b[0;32mIn[104], line 11\u001b[0m\n\u001b[1;32m      9\u001b[0m script \u001b[39m=\u001b[39m jedi\u001b[39m.\u001b[39mScript(code)\n\u001b[1;32m     10\u001b[0m \u001b[39m# script.infer(3, 16)[0].type\u001b[39;00m\n\u001b[0;32m---> 11\u001b[0m script\u001b[39m.\u001b[39;49minfer(\u001b[39m3\u001b[39;49m, \u001b[39m16\u001b[39;49m)[\u001b[39m0\u001b[39;49m]\u001b[39m.\u001b[39;49mrtype\n",
      "\u001b[0;31mAttributeError\u001b[0m: 'Name' object has no attribute 'rtype'"
     ]
    }
   ],
   "source": [
    "code = \"\"\"\n",
    "def foo(a: int):\n",
    "    return bar(str(a))\n",
    "\n",
    "def bar(b):\n",
    "    return b\n",
    "\"\"\"\n",
    "\n",
    "script = jedi.Script(code)\n",
    "# script.infer(3, 16)[0].type\n",
    "script.infer(3, 16)[0].rtype"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "code = \"\"\"\n",
    "def foo(a: int):\n",
    "    return bar(str(a))\n",
    "\n",
    "def bar(b):\n",
    "    return b\n",
    "\"\"\"\n",
    "\n",
    "script = jedi.Script(code)\n",
    "script.infer(3, 16)[0].rtype"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3.10.10 ('sweepai-u_CIt3kb-py3.10')",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.10.12"
  },
  "orig_nbformat": 4,
  "vscode": {
   "interpreter": {
    "hash": "25d341f3248a096a89b9dbf6eec8e41f63aed02f6ba059df22a49224e3e8f1b0"
   }
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
